package basics.proxy.cglibProxy;

import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.Enhancer;

import java.util.Arrays;

/**
 * @author jiangwz
 * @create 2021/3/10.
 */
public class CglibProxyFactory {

    public static Object getProxy(Class<?> clazz){
        // 创建动态代理增强类
        Enhancer enhancer = new Enhancer();
        // 设置类加载器
        enhancer.setClassLoader(clazz.getClassLoader());
        // 设置被代理类
        enhancer.setSuperclass(clazz);
        // 设置方法拦截器
        enhancer.setCallback(new DebugMethodInterceptor());
//        Callback[] callbacks = new Callback[2];
//        callbacks[0] = new DebugMethodInterceptor();
//        callbacks[1] = new DebugMethodInterceptor2();
//        enhancer.setCallbacks(callbacks);
        // 创建代理类
        return enhancer.create();
    }
}
